package kr.ac.postech.marathon.client.widgets;

import kr.ac.postech.marathon.client.HasModel;
import kr.ac.postech.marathon.client.models.Address;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class AddressForm extends Composite implements HasModel<Address> {
	
	private VerticalPanel vPanel;
	private HorizontalPanel zipCodePanel;
	
	private TextBox zipCode1;
	private TextBox zipCode2;
	
	private TextBox address1;
	private TextBox address2;
	
	public AddressForm() {
		vPanel = new VerticalPanel();
		
		// Zipcode
		zipCodePanel = new HorizontalPanel();
		zipCode1 = new TextBox();
		zipCode1.setMaxLength(3);
		zipCode1.setVisibleLength(3);
		zipCode2 = new TextBox();
		zipCode2.setMaxLength(3);
		zipCode2.setVisibleLength(3);
		zipCodePanel.add(zipCode1);
		zipCodePanel.add(new HTML("-"));
		zipCodePanel.add(zipCode2);
		vPanel.add(zipCodePanel);
		
		// Address
		address1 = new TextBox();
		address1.setEnabled(false);
		address2 = new TextBox();
		vPanel.add(address1);
		vPanel.add(address2);
		
		
		initWidget(vPanel);
	}


	
	public Address getModel() {
		Address a = new Address(
				zipCode1.getText(), 
				zipCode2.getText(), 
				address2.getText()
				);
		return a;
	}
}